//
//  RRAutoLayout.h
//  AutoLayoutTest
//
//  Created by wangrui on 14-2-24.
//  Copyright (c) 2014年 PPS. All rights reserved.
//

#import <objc/runtime.h>

#define REPLACE_METHOD(__CLASS__, __ORIG_SELECTOR__, __NEW_SELECTOR__) {                                                                            \
Method origInstanceMethod = class_getInstanceMethod(__CLASS__, __ORIG_SELECTOR__);                                                              \
Method newInstanceMethod  = class_getInstanceMethod(__CLASS__, __NEW_SELECTOR__);                                                               \
if( class_addMethod(__CLASS__, __ORIG_SELECTOR__, method_getImplementation(newInstanceMethod), method_getTypeEncoding(newInstanceMethod)) ){    \
class_replaceMethod(__CLASS__, __NEW_SELECTOR__, method_getImplementation(origInstanceMethod), method_getTypeEncoding(origInstanceMethod)); \
}else{                                                                                                                                          \
method_exchangeImplementations(origInstanceMethod, newInstanceMethod);                                                                      \
}                                                                                                                                               \
}


#define ADD_METHOD(__CLASS__, __ORIG_SELECTOR__, __NEW_SELECTOR__) {                                                                                \
Method newInstanceMethod  = class_getInstanceMethod(__CLASS__, __NEW_SELECTOR__);                                                               \
class_addMethod(__CLASS__, __ORIG_SELECTOR__, method_getImplementation(newInstanceMethod), method_getTypeEncoding(newInstanceMethod));          \
}
